package com.sxkj.entity.base;

import com.github.pagehelper.PageInfo;
import java.util.List;

/**
 * 分页类
 * @param <T>
 */
public class Page<T>{

	private Integer pageNum;
	private Integer pageSize;
	private Integer totalPage;
	private Long total;
	private List<T> list;
	private String orderBy;

	public Page() {
	}

//	public Page(List<T> list) {
//		super(list);
//	}

	/**
	 * 将PageHelper分页后的list转为分页信息
	 */
	public static <T> Page<T> restPage(List<T> list) {
		Page<T> result = new Page<T>();
		PageInfo<T> pageInfo = new PageInfo<T>(list);
		result.setTotalPage(pageInfo.getPages());
		result.setPageNum(pageInfo.getPageNum());
		result.setPageSize(pageInfo.getPageSize());
		result.setTotal(pageInfo.getTotal());
		result.setList(pageInfo.getList());
		return result;
	}

	public static <T> Page<T> restPageCollection(List<T> list) {
		Page<T> result = new Page<T>();
		PageInfo<T> pageInfo = new PageInfo<T>(list);
		result.setTotalPage(pageInfo.getPages());
		result.setPageNum(pageInfo.getPageNum());
		result.setPageSize(pageInfo.getPageSize());
		result.setTotal((long) pageInfo.getSize());
		result.setList(pageInfo.getList());
		return result;
	}

	/**
	 * 将SpringData分页后的list转为分页信息
	 */
	public static <T> Page<T> restPage(org.springframework.data.domain.Page<T> pageInfo) {
		Page<T> result = new Page<T>();
		result.setTotalPage(pageInfo.getTotalPages());
		result.setPageNum(pageInfo.getNumber());
		result.setPageSize(pageInfo.getSize());
		result.setTotal(pageInfo.getTotalElements());
		result.setList(pageInfo.getContent());
		return result;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
}
